package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("/api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    /**
     * 将数据库中的专辑信息es
     *
     * @return
     */
    @GetMapping("/albumInfoToElasticsearch")
    public Result albumInfoToElasticsearch() {
        for (int i = 1; i < 2000; i++) {
            searchService.albumToElasticsearch(i);
        }
        return Result.ok();
    }


    /**
     * 获取首页显示数据
     *
     * @param category1Id
     * @return
     */
    @GetMapping("/channel/{category1Id}")
    public Result channel(@PathVariable(value = "category1Id") Long category1Id) {
        List<Map<String, Object>> mapList = searchService.channel(category1Id);
        return Result.ok(mapList);
    }

    /**
     * 专辑搜索
     *
     * @param albumIndexQuery
     * @return
     */
    @PostMapping
    public Result albumInfo(@RequestBody AlbumIndexQuery albumIndexQuery) {
        return Result.ok(searchService.albumInfo(albumIndexQuery));
    }

    /**
     * 提示词
     * @param keyword
     * @return
     */
    @GetMapping("/completeSuggest/{keyword}")
    public Result completeSuggest(@PathVariable(value = "keyword") String keyword) {
        return Result.ok(searchService.completeSuggest(keyword));
    }

    /**
     * 获取专辑详情信息
     * @param albumId
     * @return
     */
    @GetMapping("/{albumId}")
    public Result albumInfoDetail(@PathVariable(value = "albumId") Long albumId){
        return Result.ok(searchService.albumInfoDetail(albumId));
    }

}

